﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GameBase;

namespace GalaxyPresident
{
    public abstract class Block : GameBase.VisibleGameEntity
    {
        protected PlanetEntity _entity;
        protected BBB _owner;
        protected int _blockIndex;

        protected bool isJustDestroy = false;

        public bool IsJustDestroy
        {
            get { return isJustDestroy; }
            set { isJustDestroy = value; }
        }

        public PlanetEntity Entity
        {
            get { return _entity; }
            set { _entity = value; }
        }

        public Block(BBB owner, int blockIndex, PlanetEntity planetEntity)
        {
            init(owner, blockIndex);
            _entity = planetEntity;
        }

        public Block(BBB owner, int blockIndex)
        {
            init(owner, blockIndex);
        }

        private void init(BBB owner, int blockIndex)
        {
            _owner = owner;
            _blockIndex = blockIndex;
        }

        public void buildEntity(PlanetEntity planetEntity)
        {
            _entity = planetEntity;
        }

        public void destroyEntity()
        {
            if (_owner.ViewLayer != null)
                _owner.ViewLayer.RemoveChild(Entity);
            Entity = null;
        }

        public virtual float getEconomicIncreaseAmount()
        {
            return 0;
        }

        public override void UpdateInfo(GameTime gameTime)
        {
            base.UpdateInfo(gameTime);
            if(Entity != null)
                Entity.UpdateInfo(gameTime);

            if (isJustDestroy)
            {
                _currentTotalTime += gameTime.ElapsedGameTime.Milliseconds;
                if (_currentTotalTime >= 5000)
                {
                    _currentTotalTime = 0;
                    isJustDestroy = false;
                }
            }
        }
    }
}
